<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace App\Roll\Mapper;

use App\Roll\Model\RollInfo;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * Roll房间信息Mapper类
 */
class RollInfoMapper extends AbstractMapper
{
    /**
     * @var RollInfo
     */
    public $model;

    public function assignModel()
    {
        $this->model = RollInfo::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // ID
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 房间名称
        if (isset($params['name']) && filled($params['name'])) {
            $query->where('name', 'like', '%'.$params['name'].'%');
        }

        // 排序
        if (isset($params['sort_id']) && filled($params['sort_id'])) {
            $query->where('sort_id', '=', $params['sort_id']);
        }

        // 房间图片
        if (isset($params['img']) && filled($params['img'])) {
            $query->where('img', 'like', '%'.$params['img'].'%');
        }

        // 房间类型  1：主播   2：官方
        if (isset($params['type']) && filled($params['type'])) {
            $query->where('type', '=', $params['type']);
        }

        // 主播ID
        if (isset($params['anchor_id']) && filled($params['anchor_id'])) {
            $query->where('anchor_id', '=', $params['anchor_id']);
        }

        // 满足充值金额
        if (isset($params['recharge_money']) && filled($params['recharge_money'])) {
            $query->where('recharge_money', '=', $params['recharge_money']);
        }

        // 充值开始时间
        if (isset($params['recharge_start_time']) && filled($params['recharge_start_time'])) {
            $query->where('recharge_start_time', '=', $params['recharge_start_time']);
        }

        // 充值结束时间
        if (isset($params['recharge_end_time']) && filled($params['recharge_end_time'])) {
            $query->where('recharge_end_time', '=', $params['recharge_end_time']);
        }

        // 目前房间人数
        if (isset($params['num_people']) && filled($params['num_people'])) {
            $query->where('num_people', '=', $params['num_people']);
        }

        // 房间口令
        if (isset($params['secret_signal']) && filled($params['secret_signal'])) {
            $query->where('secret_signal', 'like', '%'.$params['secret_signal'].'%');
        }

        // 用户可以进入房间的初始时间
        if (isset($params['start_time']) && filled($params['start_time'])) {
            $query->where('start_time', '=', $params['start_time']);
        }

        // 用户不能进入房间的结束时间
        if (isset($params['end_time']) && filled($params['end_time'])) {
            $query->where('end_time', '=', $params['end_time']);
        }

        // 开奖截止时间
        if (isset($params['award_time']) && filled($params['award_time'])) {
            $query->where('award_time', '=', $params['award_time']);
        }

        // 房间状态 1：待开放  2：开放中  3：已结束 
        if (isset($params['status']) && filled($params['status'])) {
            $query->where('status', '=', $params['status']);
        }

        // 创建者
        if (isset($params['created_by']) && filled($params['created_by'])) {
            $query->where('created_by', '=', $params['created_by']);
        }

        // 创建时间
        if (isset($params['create_time']) && filled($params['create_time'])) {
            $query->where('create_time', '=', $params['create_time']);
        }

        // 更新时间
        if (isset($params['update_time']) && filled($params['update_time'])) {
            $query->where('update_time', '=', $params['update_time']);
        }

        return $query;
    }
}